<?php

//initialize the session
if (!isset($_SESSION)) {
@session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
  $_SESSION['MM_id_target']=NULL;
	$_SESSION['MM_aut_target']=NULL;
	$_SESSION['MM_nmb_target']=NULL;
	$_SESSION['MM_tp_programa']=NULL;
	$_SESSION['MM_id_candidato']=NULL;
	$_SESSION['MM_id_ies']=NULL;
	
  $logoutGoTo = "../private/login.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>

<?php
if (!isset($_SESSION)) {
 @session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "../private/login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php require_once('../Connections/miportal.php'); 
mysql_query("SET NAMES 'utf8'");?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$charToBeReplaced=array("Á","É","Í","Ó","Ú","Ñ","á","é","í","ó","ú");
$charToReplace=array("A","E","I","O","U","N","a","e","i","o","u");
$deniedCharacter=array (" ","-","_","(",")","\\","/","\"");
$extensionDenied = array(".php",".css",".xls",".csv",".exe",".bat", ".sql",".html",".js",".htm","htm",".asp",".aspx",">","<","?","include",".phtml",".exe");

$id_ies_beneficiada = "-1";
if (isset($_POST['object'])) {
  $id_ies_beneficiada = base64_decode($_POST['object'])-261;
}


mysql_select_db($database_miportal, $miportal);
$querry_sl_convenio="SELECT * FROM cor_ies_beneficiada JOIN cat_convenio USING (id_cor_ies_beneficiada) WHERE id_cor_ies_beneficiada = $id_ies_beneficiada";
$rs_convenio= mysql_query($querry_sl_convenio, $miportal) or die(mysql_error());
$row_convenio = mysql_fetch_assoc($rs_convenio);
$total_row_convenio = mysql_num_rows($rs_convenio);
//Obtenemos Datos del RIV
	/*mysql_select_db($database_miportal, $miportal);
	$query_rs_RIV ="SELECT * FROM  cat2_usuario WHERE cat2_usuario.tp_perfil='RIV' AND cat2_usuario.tp_validacion=11 AND id_target=$id_ies_beneficiada LIMIT 1";
	$rs_query_RIV = mysql_query($query_rs_RIV, $miportal) or die(mysql_error());
	$row_rs_RIV= mysql_fetch_assoc($rs_query_RIV);
	$totalRows_rs_RIV = mysql_num_rows($rs_query_RIV);
	
	*/
	
$id_ies_rs= $row_convenio['id_cat_ies'];
$ies_convocatoria= $row_convenio['id_cat_convocatoria'];
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$update_sql_file_location="";
#Establecemos la ruta de los archivos NOTA: Se debe crear la restricció por query para bloquear el permiso en caso de que la IES no participe en la convocatoria.
$dir_convenio_ies = "../docs/convenios/".$ies_convocatoria."/".$id_ies_rs."/";
$documents_array=array(
'url_convenio',
'url_comp_fiscal',
'url_comp_xml'
);
/*
$programa="";
$header_ = "MIME-Version:1.0\r\n Content-type:text/html; charset=UTF-8\r\n";
$header_ .= "From:FESE<administracion@fese.org.mx>";
$mensaje_email_transferencia="Buen día,\n
Por medio del presente me permito informarle que se ha realizado la transferencia de fondos correspondientes al mes en curso, con la finalidad de ser dispersados entre los beneficiarios del programa a más tardar el último día hábil del mes.\n
El comprobante de la misma lo podrá descargar en MI PORTAL FESE en (miportal.fese.org.mx) y por única ocasión también será remitido vía correo electrónico.\n
Se le recuerda que tiene hasta el décimo día del mes para enviar puntualmente su recibo y/o factura correspondiente, ya que la siguiente transferencia será liberado con el recibo correspondiente del depósito previo.\n
Sin  más por el momento, agradecemos su atención y quedamos a sus órdenes para cualquier duda y/o aclaración.\n
";
$mensaje_email_update="Se han actualizado los comprobantes de la universidad \" ".$row_convenio['id_nmbNombre']."\". \n Se agrego un nuevo comprobante para el programa: ";
if(isset($_SESSION['MM_id_cat_convocatoria'])&&$_SESSION['MM_id_cat_convocatoria']!=0 ){
	if($_SESSION['MM_id_cat_convocatoria']==17) $mensaje_email_update.= $programa="BECAS VINCULACIÓN";
	if($_SESSION['MM_id_cat_convocatoria']==18) $mensaje_email_update.= $programa="EXPERIMENTA";
	if($_SESSION['MM_id_cat_convocatoria']==19) $mensaje_email_update.=  $programa="EMPLEATE";
	if($_SESSION['MM_id_cat_convocatoria']==20) $mensaje_email_update.= $programa="MI PRIMERA EMPRESA";
};
$email="administracion@fese.org.mx,,spaz@fese.org.mx,otorres@fese.org.mx,".$row_rs_RIV['inf_correo_p'];*/

if ((isset($_POST["MM_update_convenio"])) && ($_POST["MM_update_convenio"]=="formConvenio")) {
 $status_convenio=-1;
 $update_document=NULL;
 
 if(isset($_POST['solicitud'])&&$_POST['solicitud']=="on"){
	 $status_convenio=1;
	 $update_document="fh_solicitud";
 } if(isset($_POST['enviado'])&&$_POST['enviado']=="on"){
	 $status_convenio=2;
	 $update_document="fh_enviado_firma";
 }if(isset($_POST['validado'])&&$_POST['validado']=="on"){
	 $status_convenio=3;
	 $update_document="fh_validando";
 }if(isset($_POST['enfirma'])&&$_POST['enfirma']=="on"){
	 $status_convenio=4;
	 $update_document="fh_en_firma";
 }if(isset($_POST['digitalizado'])&&$_POST['digitalizado']=="on"){
	 $status_convenio=5;
	 $update_document="fh_digitalizado";
 }if(isset($_POST['enviadofinal'])&&$_POST['enviadofinal']=="on"){
	 $status_convenio=6;
	 $update_document="fh_envio_ies";
 }if(isset($_POST['entregado'])&&$_POST['entregado']=="on"){
	 $status_convenio=7;
	 $update_document="fh_entrega_ies";
 }
 	
	if($row_convenio['tp_status_convenio']<=$status_convenio){
 $update_sql_file_location=
			  'UPDATE cat_convenio SET tp_status_convenio='.$status_convenio.', '. $update_document.'=NOW() WHERE id_cor_ies_beneficiada='.$row_convenio['id_cor_ies_beneficiada'];
		  mysql_select_db($database_miportal, $miportal);
		  $Result = mysql_query($update_sql_file_location, $miportal) or die(mysql_error().$update_sql_file_location);
	}
	
	//header("Location:../report/report_juridico_convenio.php");
	echo '
	<script type="text/javascript">
	window.location="../report/report_juridico_convenio.php";</script>';
}

					


?>
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximun-scale=1">
<title>FUNDACIÓN EDUCACIÓN SUPERIOR-EMPRESA</title>
</head>
<body>
  Error
</body>
</html>

